//package com.art.filter;
//
//import com.art.entity.User;
//import com.art.servlet.LoginServlet;
//import jakarta.servlet.FilterChain;
//import jakarta.servlet.ServletException;
//import jakarta.servlet.annotation.WebFilter;
//import jakarta.servlet.http.HttpFilter;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import jakarta.servlet.http.HttpSession;
//
//import java.io.IOException;
//
///**
// * IntelliJ IDEA
// *
// * @author 谭礼赞 2038940123
// * @since 2022-11-07-2022/11/7
// */
//
//@WebFilter("/*")
//public class MainFilter extends HttpFilter {
//
//    @Override
//    protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException {
//        //获取网址
//        String url = req.getRequestURL ().toString ();
//
//        //判断是否请求静态资源、登录界面
//        if(url.contains("/assets/")||url.contains ( "Login.jsp" )){
//            //放行
//            chain.doFilter ( req, res );
//        }else {
//
//            HttpSession session = req.getSession ();
//            User user = (User) session.getAttribute ( "user" );
//            //判断是否登录
//            if(user!=null){
//                chain.doFilter ( req, res );
//            }else {
//                res.sendRedirect ( "Login.jsp" );
//            }
//        }
//
//        //if (!url.contains ( "/assets/" ) && !url.endsWith ( "login.html" )) {
//        //    HttpSession session = req.getSession ();
//        //    User user = (User) session.getAttribute ( "user" );
//        //    //如果用户名为空，拦截登录
//        //    if (user == null) {
//        //        System.out.println ("用户名为空");
//        //        res.sendRedirect ( "login.html" );
//        //        return;
//        //    }
//        //}
//        //chain.doFilter ( req, res );
//    }
//}
